﻿using FigureDraw;
using FigureDraw.Graphic;
using FigureDraw.Shapes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FigureDraw.Diagram;
using FigureDraw.Graphic.GDIPlus;
using FigureDraw.Graphic.Cairo;
using FigureDraw.Shapes.Effect;

namespace TestGUI
{
    public partial class Form1 : Form
    {
        MyPicture picture;
        CommonGraphic graphic;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //BlockDiagram diagram = ActivityDiagram.Instance();
            //BlockDiagram diagram = FlowchartDiagram.Instance();
            BlockDiagram diagram = DataFlowDiagram.Instance();

            //graphic = new GDIPlusScreenGraphic(pDraw.CreateGraphics());
            //graphic = new GDIPlusSVGGraphic("D:/GDIPlusSVGGraphic.svg");
            //graphic = new GDIPlusPNGGraphic("D:/GDIPlusPNGGraphic.png");
            //graphic = new GDIPlusJPEGGraphic("D:/GDIPlusSVGGraphic.jpg");

            graphic = new CairoScreenGraphic(pDraw.CreateGraphics());
            //graphic = new CairoSVGGraphic("D:/CairoSVGGraphic.svg");
            //graphic = new CairoPNGGraphic("D:/CairoPNGGraphic.png");
            //graphic = new CairoJPEGGraphic("D:/CairoPNGGraphic.jpg");

            picture = new MyPicture();

            MyShape shape;

            //Begin
            shape = diagram.DrawBegin(new MyPoint(0, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 10);
            picture.Add(new MyShadow(new MyHighlight(new MyBorder(shape))));

            //Input
            shape = diagram.DrawInput(new MyPoint(100, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyShadow(new MyBorder(new MyHighlight(shape))));

            //Process
            shape = diagram.DrawProcess(new MyPoint(200, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 3.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyBorder(new MyShadow(new MyHighlight(shape))));

            //Output
            shape = diagram.DrawOutput(new MyPoint(300, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyBorder(new MyHighlight(new MyShadow(shape))));

            //Move
            shape = diagram.DrawMove(new MyPoint(400, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyHighlight(new MyBorder(new MyShadow(shape))));


            //Condition
            shape = diagram.DrawCondition(new MyPoint(500, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyHighlight(new MyShadow(new MyBorder(shape))));

            //End
            shape = diagram.DrawEnd(new MyPoint(600, 10), new MyPoint(70, 70));
            shape.StrokeColor = new MyColorInfo(0, 255, 0);
            shape.StrokeWidth = 5.0;
            shape.BrushColor = new MyColorInfo(0, 0, 255);
            picture.Add(new MyBorder(shape));

            picture.ConvertTo(ActivityDiagram.Instance());
            picture.ConvertTo(FlowchartDiagram.Instance());
            picture.ConvertTo(DataFlowDiagram.Instance());

            //Draw();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            Draw();
        }

        private void rbCairo_CheckedChanged(object sender, EventArgs e)
        {
            graphic = new CairoScreenGraphic(pDraw.CreateGraphics());
            Draw();
        }

        private void rbGDIPlus_CheckedChanged(object sender, EventArgs e)
        {
            graphic = new GDIPlusScreenGraphic(pDraw.CreateGraphics());
            Draw();
        }

        private void Draw()
        {
            pDraw.Invalidate();
            pDraw.Refresh();

            picture.Draw(graphic);
        }
    }
}
